package com.cardone.common.template.support;

import org.apache.commons.lang.StringUtils;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.CachePut;
import org.springframework.cache.annotation.Cacheable;

import com.cardone.common.cache.support.CacheEvictSupport;

/**
 * 模板解析支持缓存
 * 
 * @author yaoht
 * 
 */
public class TemplateSupportCache implements CacheEvictSupport {
	/**
	 * 获取模板缓存键名
	 */
	private static final String GET_TEMPLATE_STRING_CACHE_KEY = "#root.targetClass.name+'.'+'getTemplateString('+#templateId+')'";

	/**
	 * 获取：模板缓存
	 * 
	 * @param templateId
	 *            模板缓存标识
	 * @return 模板缓存
	 */
	@Cacheable(value = TemplateSupport.BEAN_ID, key = TemplateSupportCache.GET_TEMPLATE_STRING_CACHE_KEY)
	public String getTemplateString(final String templateId) {
		return StringUtils.EMPTY;
	}

	@Override
	@CacheEvict(value = TemplateSupport.BEAN_ID, allEntries = true)
	public void reload() {
	}

	/**
	 * 设置：模板缓存
	 * 
	 * @param templateId
	 *            模板缓存标识
	 * @param templateString
	 *            模板缓存
	 * @return 模板缓存
	 */
	@CachePut(value = TemplateSupport.BEAN_ID, key = TemplateSupportCache.GET_TEMPLATE_STRING_CACHE_KEY)
	public String setTemplateString(final String templateId, final String templateString) {
		return templateString;
	}
}
